<?php
namespace Api\Controller;

use Think\Controller;

/**
 * 活动接口
 */
class ActiveController extends PublicController
{

    public function lists()
    {
        $p = I('p', 1, 'intval');
        $limit = I('limit', 10, 'intval');

        $filter = [
            // 'begin_date' => ['$lte' => date('Ymd', NOW_TIME)],
        ];
        $total = 0;
        $list = event('Active')->lists($filter, '', $p, $limit, $total);

        foreach ($list as &$value) {
            if (NOW_TIME < strtotime($value['begin_date'])) {
                $value['status'] = 1; // 未开始
            } elseif (NOW_TIME > strtotime($value['end_date'])) {
                $value['status'] = 3; // 已结束
            } else {
                $value['status'] = 2; // 进行中
            }
            $value['begin_time'] = strtotime($value['begin_date']);
            $value['end_time'] = strtotime($value['end_date']);
        }

        $this->success('', ['list' => $list, 'total' => intval($total)]);
    }
}